#ifndef __COMMON__
#define __COMMON__
#define CAMERA_LONG "camera"
#define CAMERA_SHORT 'c'
#define EXCLUDE_LONG "exclude"
#define EXCLUDE_SHORT 'e'
#define FILTER_LONG "filter"
#define FILTER_SHORT 'f'
#define TO_LONG "to"
#define TO_SHORT 't'
#define NAME_LONG "name"
#define NAME_SHORT 'n'
#define MOUNT_LONG "mount"
#define MOUNT_SHORT 'm'
#define LOG_LONG "log"
#define LOG_SHORT 'l'
#define APPEND_LONG "append"
#define APPEND_SHORT 'a'
#define HELP_LONG "help"
#define HELP_SHORT 'h'
//#define ALL_SHORT "e:f:t:n:m:l:a:h"
#define ALL_SHORT "e:f:t:n:m:a:h"
#define QUERY_PROGRESS "query"
#define LOG_NAME "camera.log"
#define CMD_LEN 256
#define MAX_PAYLOAD 512
#define KUNIT 1024
#define READ_ARGS_ERR -2
#define BUILD_TREE_ERR -3
#define ALLOC_ELEM_ERR -4
#define FIND_ELEM_ERR -5
#define FIND_ARGS_ERR -6
#define ALOC_SKB_ERR -7
#define TEST
#define PARSE_ARGS 1
#define BUILD_TREE 2
#define BLOCK_COPY 3
#define RECV_TIMEOUT 30

extern int test_code;

typedef struct str_node {
	int seq; //start from 0
	char* str;
	struct str_node* next;
} str_node;

typedef struct args {
	str_node* camera_path_head;
	str_node* camera_path_tail;
	str_node* exclude_path_head;
	str_node* exclude_path_tail;
	str_node* filter_head;
	str_node* filter_tail;
	char* save_to;
	char* name;
	char* log_to;
	char* mount_to;
	int append_space;
	int block_size;
} args;

void set_save_to(args*, const char*);
void set_log_to(args*, const char*);
void set_mount_to(args*, const char*);
void set_name(args*, const char*);
void set_append_space(args*, const char*);
void clean_args(args*);
void print_args(args*);
void print_str_node(str_node*);
str_node* remove_node(str_node*);
str_node* append_node(str_node*, const char*);

#ifndef CAMERA_KERNEL
#include <stdio.h>
#include <errno.h>
#define CAMERA_EXIT(MSG)			\
        do {					\
                perror(MSG);			\
                exit(EXIT_FAILURE);		\
        } while(0)
#define CAMERA_STDOUT printf
#define CAMERA_LOG print_log
#define CAMERA_STDOUT_THEN_LOG(FMT, ...)	\
        printf(FMT, ##__VA_ARGS__);		\
        print_log(FMT, ##__VA_ARGS__)
#else
#define CAMERA_STDOUT(FMT, ...) print_kernel(get_std_file, 0, FMT, ##__VA_ARGS__)
#define CAMERA_LOG(FMT, ...) print_kernel(get_log_file, 1, FMT, ##__VA_ARGS__)
#endif
#endif
